# ***********************************************************************************
# Port of swrc088c from IAR to sdcc Compiler
# ***********************************************************************************

CC=sdcc
CCASM=sdas8051

CFLAGS = --model-large

# add defines
CFLAGS+=-DMRFI_CC1111 -DMRFI -DMRFI_MAX_PAYLOAD_SIZE=53 -DMAX_HOPS=1 -Dchip=1111 -DBSP_CONFIG_CLOCK_MHZ=24 -DMCU_H="ioCC1111.h"

LFLAGS= --out-fmt-ihx --xram-loc 0xf000 --xram-size 0xF00 --iram-size 0x100 --code-loc 0x0000 --code-size 0x8000 

OBJECTS=\
apps/simple_hid/simple_hid_dongle.rel \
apps/common/mrfi_link.rel \
components/simpliciti/mrfi/mrfi.rel \
components/simpliciti/bsp/bsp.rel \
components/utils/util_buffer.rel \
components/common/hal_int.rel \
components/common/cc8051/adc.rel \
components/radios/ccxx10/hal_mcu.rel \
components/radios/ccxx10/hal_timer_32k.rel \
components/radios/ccxx10/clock.rel \
components/targets/ccxx11_dongle/hal_board.rel \
components/targets/ccxx11_dongle/hal_led.rel \
components/targets/ccxx11_dongle/hal_button.rel \
components/targets/ccxx11_dongle/hal_assert.rel \
components/usb/library/usb_descriptor_parser.rel \
components/usb/library/usb_framework.rel \
components/usb/library/usb_standard_requests.rel \
components/usb/library/ccxx11/usb_interrupt.rel \
components/usb/library/ccxx11/usb_suspend.rel \
components/usb/class_hid/usb_firmware_library_config.rel \
components/usb/class_hid/usb_hid_descriptor.rel \
components/usb/class_hid/usb_hid.rel \
components/usb/class_hid/usb_hid_hooks.rel \
components/usb/class_hid/usb_hid_reports.rel \
components/usb/class_hid/usb_class_requests.rel

# add includes files
INCLUDES=-Iapps/simple_hid \
	-Icomponents/simpliciti/mrfi \
	-Icomponents/simpliciti/bsp \
	-Icomponents/simpliciti/bsp/drivers \
	-Icomponents/simpliciti/bsp/boards/rfusb \
	-Icomponents/utils \
	-Icomponents/common \
	-Icomponents/common/cc8051 \
	-Icomponents/targets/interface \
	-Icomponents/radios/ccxx10 \
	-Icomponents/targets/ccxx11_dongle \
	-Icomponents/usb/library \
	-Icomponents/usb/class_hid

# main target
all: c1111_hid.hex

%.rel: %.s51
	$(CCASM) -x -l -o $@ $<

%.rel: %.c
	$(CC) $(INCLUDES) -c -o $@ $< $(CFLAGS)

c1111_hid.hex: $(OBJECTS)
	$(CC) $(LFLAGS) $(CFLAGS) -o $@ $^
	packihx c1111_hid.hex > image.hex

clean:
	rm -f *.hex *.lk *.map *.mem *.cdb *.omf
	rm -f *.rel */*.rel */*/*.rel */*/*/*.rel */*/*/*/*.rel
	rm -f *.asm */*.asm */*/*.asm */*/*/*.asm */*/*/*/*.asm
	rm -f *.lst */*.lst */*/*.lst */*/*/*.lst */*/*/*/*.lst
	rm -f *.sym */*.sym */*/*.sym */*/*/*.sym */*/*/*/*.sym
	rm -f *.rst */*.rst */*/*.rst */*/*/*.rst */*/*/*/*.rst

